<?php
define('current_dir', dirname(__FILE__) . '/');
global $_GLOBAL;
include_once(current_dir . 'common.php');
//=====================================
include_once("Mobile_Detect.php");
$detect = new Mobile_Detect();
 
if (!$detect->isMobile()) {
    echo "请用手机访问。";
    exit;
}
//=====================================
$c = new common();
$pwchk = $_COOKIE['ydb_mobile_userinfo']; $source=0;
if($pwchk) {
	$arrpw = $c->eccode($_COOKIE['ydb_mobile_userinfo'], 'DECODE', db_pscode);
	$arr = explode("|",$arrpw);
	$source = $arr[1];  //预订员ID
}
if(!$pwchk || !$source) {
	header('Location: index.php');
}
$action = $c->accept('action', 'P');
if($action == "reg") {
	$alias = $c->accept('alias', 'P');
	$mobile = $c->accept('mobile', 'P');
	$username = $mobile;
	$err = 0;
	if($username == ''){
		$err = -1;
	}
	if (!preg_match("/^1[0-9]{10}$/", $username)) {
		$err = -2;
	}
	$password = mt_rand(10000000, 99999999);
	$password2 = md5($password);
	
	$ipadd = $c->ip($_SERVER['REMOTE_ADDR']);
	$addtime = time();
	$isclass = 1;
	$c->init();
	$db_table = db_prefix . "member";
	$db_where = " WHERE username='$username'";
	$user = $_GLOBAL['db']->fetch_first("SELECT * FROM $db_table $db_where");
	if(!$user) {
		$db_field = 'username,password,email,sex,birthday,country,province,city,district,alias,mobile,integral,visitcount,lastip,addtime,lasttime,mcid,source,isclass';
		$db_values = "'$username','$password2','',0,0,0,0,0,0,'$alias','$mobile',0,0,$ipadd,$addtime,$addtime,1,$source,$isclass";
		$_GLOBAL['db']->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
		$c->membersmssend('mobileregsms',$username,$password);
		$err = 1;
	} else {
		$err = -6;
	}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="mobile.css" />
<title>客人注册</title>
</head>
<body>
<div class="mobile">
	<div class="t">客人注册</div>
	<form name="mainform" method="post" action="guestreg.php">
    <dl>
    	<dd><label>姓名：</label><input type="text" id="alias" class="u" size="20" name="alias" value="" /></dd>
        <dd><label>手机：</label><input type="text" id="mobile" class="u" size="20" name="mobile" value="" /></dd>
        <dd class="<?php if($err==1) { echo "success";} else { echo "text";}?>"><?php echo  $c->message($err);?></dd>
        <dd class="slogin"><input type="hidden" id="action" name="action" value="reg" /><input name="submit" type="submit" class="buttonface" value="注册"/></dd>
    </dl>
    </form>
</div>
</body>
</html>